using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Reflection;
using System.Collections;
using System.Collections.Generic;
using Gizmox.WebGUI.Forms;

namespace VisualDB.Helpers
{
    public class UtilityHelper
    {
        public static DataTable GetDataTableFromArray(object[] array)
        {
            DataTable table = new DataTable(array[0].GetType().Name);

            PropertyInfo[] properties = array[0].GetType().GetProperties();

            foreach (PropertyInfo property in properties)
            {
                table.Columns.Add(property.Name, property.PropertyType);
            }

            foreach (object obj in array)
            {
                DataRow row = table.NewRow();

                foreach (PropertyInfo property in properties)
                {
                    object value = property.GetValue(obj, null);

                    row[property.Name] = value;
                }

                table.Rows.Add(row);
            }

            return table;
        }

        public static bool ConvertToBool(object obj)
        {
            return (obj == null || obj == DBNull.Value || !Convert.ToBoolean(obj)) ? false : true;
        }
    }
}
